package com.hxh.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/7/3 21:59
 */
@Controller
@ResponseBody
public class TestController {

    @Value("${myTestConfigName}")  // 获取自定义配置项
    private String myTestConfigName;

    @Value("${string.myString1}")
    private String myString01;

    @Value("${string.myString2}")
    private String myString02;

    @Value("${string.myString3}")
    private String myString03;

    @Value("${myString}")
    private String myString;

    @Autowired
    private Student student;

    @PostConstruct
    public void postConstruct() {
        System.out.println("student: " + student);
    }

    @RequestMapping("/hi")
    public String sayHi(String name) {
        if (!StringUtils.hasLength(name)) {
            name = "DEFAULT NAME";
        }
        return "Hi! " + name;
    }

    @RequestMapping("/getConfig")
    public String getConfig() {
        return "myTestConfigName: " + myTestConfigName + "<br>"
                + "myString01: " + myString01 + "<br>"
                + "myString02: " + myString02 + "<br>"
                + "myString03: " + myString03 + "<br>"
                + "myString: " + myString + "<br>"
                + "student: " + student;
    }
}
